<template>
  <div class="list-page-container">
    <a-card>
      <a-form layout="inline" @keyup.enter.native="handleSearch">
        <a-row :gutter="24">
          <a-col :md="6" :sm="24">
            <CompositeSearch
              :fieldList="fieldList"
              @getParams="getSearchValue"
              @adSearch="onAdSearch"
              @adClear="onAdClear"
              @tagClick="onTagClick">
              <template v-slot:ad-search-content>
                <a-form-model
                  ref="adSearchFormRef"
                  :model="adSearchFormData"
                  layout="vertical">
                  <a-row :gutter="24">
                    <a-col :span="24">
                      <a-form-model-item label="供应商状态">
                        <ASelectList v-model="adSearchFormData.supplierStatus" :isHasDict="false" :defaultOption="supplierStatusOption" />
                      </a-form-model-item>
                    </a-col>
                  </a-row>
                  <a-row :gutter="24">
                    <a-col :span="24">
                      <a-form-model-item label="审批状态">
                        <ASelectList v-model="adSearchFormData.approveStatus" :isHasDict="false" :defaultOption="approveStatusOption"/>
                      </a-form-model-item>
                    </a-col>
                  </a-row>
                  <a-row :gutter="24">
                    <a-col :span="24">
                      <a-form-model-item label="创建时间">
                        <a-range-picker
                          v-model="createTime"
                          format="YYYY-MM-DD"
                          style="width:100%;"
                          @change="(timeRange, timeStringRange) => setTimeRange('createTimeStart', 'createTimeEnd', timeRange, timeStringRange)"/>
                      </a-form-model-item>
                    </a-col>
                  </a-row>
                </a-form-model>
              </template>
            </CompositeSearch>
          </a-col>
          <a-col :md="18" :sm="24">
            <div class="space-btn">
              <a-button @click="onExport">导出</a-button>
              <a-button type="danger" @click="onDelete">删除</a-button>
            </div>
          </a-col>
        </a-row>
      </a-form>
      <a-table
        ref="table"
        rowKey="id"
        size="middle"
        bordered
        :loading="loading"
        :columns="columns"
        :dataSource="dataSource"
        :row-selection="{ fixed: true, selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        :scroll="{ x: '100%', autoHeight: true }"
        :pagination="pagination">
        <span slot="date" slot-scope="text">{{ text | DateFormat }}</span>
        <span slot="amount" slot-scope="text">{{ text | AmountFormat }}</span>
        <template slot="supplierStatus" slot-scope="text"><span>{{ supplierStatusEnum[text] || '' }}</span></template>
        <template slot="approveStatus" slot-scope="text"><span>{{ approveStatusEnum[text] || '' }}</span></template>
        <span slot="qualificationCertificate" slot-scope="text, record">
          <span v-if="['4'].includes(record.approveStatus)" class="cus-text" pointer>编辑</span>
          <template v-else>
            <span v-if="record.qualificationCertificate === '1'" class="cus-text" pointer>待录入</span>
            <span v-else class="cus-text" pointer>查看</span>
          </template>
        </span>
        <span slot="factoryInspectionVisit" slot-scope="text, record">
          <span v-if="['4'].includes(record.approveStatus)" class="cus-text" pointer>编辑</span>
          <template v-else>
            <span v-if="record.factoryInspectionVisit === '1'" class="cus-text" pointer>待录入</span>
            <span v-else class="cus-text" pointer>查看</span>
          </template>
        </span>
        <span slot="sampleCertification" slot-scope="text, record">
          <span v-if="['4'].includes(record.approveStatus)" class="cus-text" pointer>编辑</span>
          <template v-else>
            <span v-if="record.sampleCertification === '1'" class="cus-text" pointer>待录入</span>
            <span v-else class="cus-text" pointer>查看</span>
          </template>
        </span>
        <template slot="action" slot-scope="text, record">
          <span v-show="['1'].includes(record.approveStatus)" class="cus-text" pointer @click="onSubmitApproval(record)">提交审批</span>
          <span v-show="['4'].includes(record.approveStatus)" class="cus-text" pointer @click="onSubmitApproval(record)">再次提交</span>
          <span v-show="['1', '4'].includes(record.approveStatus)" class="cus-text" pointer @click="onEdit">编辑</span>
          <span v-show="['2', '3'].includes(record.approveStatus)" class="cus-text" pointer @click="onCheck">查看</span>
        </template>
      </a-table>
    </a-card>

    <AdmittanceDetail ref="AdmittanceDetail" />
  </div>
</template>

<script>
import ListPageMixin from '@/mixins/ListPageMixin.js';
import optionsMixin from '@views/supplier-manage/admittance/optionsMixin.js'
import AdmittanceDetail from '@views/supplier-manage/admittance/detail.vue'

export default {
  name: 'AdmittanceIndex',
  mixins: [ ListPageMixin, optionsMixin ],
  components: {
    AdmittanceDetail
  },
  data() {
    return {
      adSearchFormData: {
        supplierStatus: '',
        approveStatus: '',
        createTimeStart: '',
        createTimeEnd: '',
      },
      createTime: [],
      dataSource: [],
      originalDataSource: [
        {
          supplierStatus: '2',
          createTime: '2025-1-10 12:00:00',
          approveStatus: '1',
          supplierName: '河南盛世机械工具集团有限公司',
          supplierProductType: '包装材料供应商',
          nainSupplyProduct: '美机原材料',
          qualificationCertificate: '1',
          factoryInspectionVisit: '1',
          sampleCertification: '1',
          supplierCode: 'GYS6667787990',
          enterpriseScale: '小型',
          annualRevenue: '2500000',
          contactAddress: '广州市黄埔区黄埔东路1号',
          level: 'A',
          enterpriseName: '河南盛世机械工具集团有限公司',
          taxpayerNumber: '91320238977384',
          enterpriseStatus: '存续(开业)',
          setUpTime: '2025-1-10 12:00:00',
          legalRepresentative: '杨先生',
          registeredCapital: '300万元人民币',
          paidCapital: '300万元人民币',
          enterpriseNature: '有限责任公司',
          icInfoUpdateTime: '2025-1-10 12:00:00',
          registeredAddress: '广州市黄埔区',
          businessScope: '互联网、互联网软件、技术服务咨询',
          enterpriseQueryResult: '2023-06-08【有效请求】查询成功',
          inquiryChannel: '天眼查',
        },
        {
          supplierStatus: '2',
          createTime: '2025-1-10 12:00:00',
          approveStatus: '2',
          supplierName: '广州三五零配件有限公司',
          supplierProductType: '包装材料供应商',
          nainSupplyProduct: '美机原材料',
          qualificationCertificate: '2',
          factoryInspectionVisit: '2',
          sampleCertification: '2',
          supplierCode: 'GYS6667787990',
          enterpriseScale: '中型',
          annualRevenue: '2500000',
          contactAddress: '广州市黄埔区黄埔东路1号',
          level: 'A',
          enterpriseName: '广州三五零配件有限公司',
          taxpayerNumber: '91320238977384',
          enterpriseStatus: '存续(开业)',
          setUpTime: '2025-1-10 12:00:00',
          legalRepresentative: '杨先生',
          registeredCapital: '300万元人民币',
          paidCapital: '300万元人民币',
          enterpriseNature: '有限责任公司',
          icInfoUpdateTime: '2025-1-10 12:00:00',
          registeredAddress: '广州市黄埔区',
          businessScope: '互联网、互联网软件、技术服务咨询',
          enterpriseQueryResult: '2023-06-08【有效请求】查询成功',
          inquiryChannel: '天眼查',
        },
        {
          supplierStatus: '2',
          createTime: '2025-1-10 12:00:00',
          approveStatus: '4',
          supplierName: '广汽集团广天有限公司',
          supplierProductType: '包装材料供应商',
          nainSupplyProduct: '美机原材料',
          qualificationCertificate: '2',
          factoryInspectionVisit: '2',
          sampleCertification: '2',
          supplierCode: 'GYS6667787990',
          enterpriseScale: '大型',
          annualRevenue: '2500000',
          contactAddress: '广州市黄埔区黄埔东路1号',
          level: 'A',
          enterpriseName: '广汽集团广天有限公司',
          taxpayerNumber: '91320238977384',
          enterpriseStatus: '存续(开业)',
          setUpTime: '2025-1-10 12:00:00',
          legalRepresentative: '杨先生',
          registeredCapital: '300万元人民币',
          paidCapital: '300万元人民币',
          enterpriseNature: '有限责任公司',
          icInfoUpdateTime: '2025-1-10 12:00:00',
          registeredAddress: '广州市黄埔区',
          businessScope: '互联网、互联网软件、技术服务咨询',
          enterpriseQueryResult: '2023-06-08【有效请求】查询成功',
          inquiryChannel: '天眼查',
        },
        {
          supplierStatus: '4',
          createTime: '2025-1-10 12:00:00',
          approveStatus: '3',
          supplierName: '河南盛世机械工具集团有限公司',
          supplierProductType: '包装材料供应商',
          nainSupplyProduct: '美机原材料',
          qualificationCertificate: '2',
          factoryInspectionVisit: '2',
          sampleCertification: '2',
          supplierCode: 'GYS6667787990',
          enterpriseScale: '小型',
          annualRevenue: '2500000',
          contactAddress: '广州市黄埔区黄埔东路1号',
          level: 'A',
          enterpriseName: '河南盛世机械工具集团有限公司',
          taxpayerNumber: '91320238977384',
          enterpriseStatus: '存续(开业)',
          setUpTime: '2025-1-10 12:00:00',
          legalRepresentative: '杨先生',
          registeredCapital: '300万元人民币',
          paidCapital: '300万元人民币',
          enterpriseNature: '有限责任公司',
          icInfoUpdateTime: '2025-1-10 12:00:00',
          registeredAddress: '广州市黄埔区',
          businessScope: '互联网、互联网软件、技术服务咨询',
          enterpriseQueryResult: '2023-06-08【有效请求】查询成功',
          inquiryChannel: '天眼查',
        },
        {
          supplierStatus: '3',
          createTime: '2025-1-10 12:00:00',
          approveStatus: '3',
          supplierName: '广州三五零配件有限公司',
          supplierProductType: '包装材料供应商',
          nainSupplyProduct: '美机原材料',
          qualificationCertificate: '2',
          factoryInspectionVisit: '2',
          sampleCertification: '2',
          supplierCode: 'GYS6667787990',
          enterpriseScale: '中型',
          annualRevenue: '2500000',
          contactAddress: '广州市黄埔区黄埔东路1号',
          level: 'A',
          enterpriseName: '广州三五零配件有限公司',
          taxpayerNumber: '91320238977384',
          enterpriseStatus: '存续(开业)',
          setUpTime: '2025-1-10 12:00:00',
          legalRepresentative: '杨先生',
          registeredCapital: '300万元人民币',
          paidCapital: '300万元人民币',
          enterpriseNature: '有限责任公司',
          icInfoUpdateTime: '2025-1-10 12:00:00',
          registeredAddress: '广州市黄埔区',
          businessScope: '互联网、互联网软件、技术服务咨询',
          enterpriseQueryResult: '2023-06-08【有效请求】查询成功',
          inquiryChannel: '天眼查',
        },
      ]
    }
  },
  created() {
    this.handleSearch();
  },
  methods: {
    // 获取 搜索框参数
    getSearchValue(currentValue, selectFiledList) {
      console.log(currentValue, selectFiledList, 'getSearchValue');
      this.handleSearch();
    },
    // 确定搜索 高级搜索
    onAdSearch() {
      console.log(this.adSearchFormData, '确定搜索 高级搜索');
      this.handleSearch();
    },
    // 重置 高级搜索
    onAdClear() {
      console.log('重置 高级搜索');
    },
    onTagClick(data) {
      console.log(data, 'onTagClick');
      const { name } = data;
      if (['筛选组合01', '筛选组合02', '筛选组合03'].includes(name)) {
        this.adSearchFormData.supplierStatus = '1';
        this.adSearchFormData.approveStatus = '1';
      } else if (['筛选组合04', '筛选组合05', '筛选组合06'].includes(name)) {
        this.adSearchFormData.supplierStatus = '2';
        this.adSearchFormData.approveStatus = '2';
      } else {
        this.adSearchFormData.supplierStatus = '3';
        this.adSearchFormData.approveStatus = '3';
      }
    },
    handleSearch() {
      this.loading = true;
      setTimeout(() => {
        this.loading = false;
        this.onSelectClear();
        this.dataSource = this.originalDataSource
      }, 100)
    },
    // 导出
    onExport() {

    },
    // 删除
    onDelete() {
      console.log(this.selectedRowKeys, this.selectedRows, 'onDelete');
      if (this.selectedRowKeys.length) {
        this.$confirm({
          title: '批量删除',
          content: '确认批量删除？',
          okText: '确认',
          cancelText: '取消',
          onOk: () => {
            this.handleSearch();
            this.$message.success(`批量删除成功`);
          }
        });
      } else {
        this.$message.error(`请选择数据！`);
      }
    },
    onSubmitApproval(record) {
      const { qualificationCertificate, factoryInspectionVisit, sampleCertification } = record;
      const state1 = qualificationCertificate === '1';
      const state2 = factoryInspectionVisit === '1';
      const state3 = sampleCertification === '1';
      this.$confirm({
        title: '是否提交审批操作？',
        content: h => <div>
          { state1 && <div style="color:red;">资质证件为空</div> }
          { state2 && <div style="color:red;">验厂考察为空</div> }
          { state3 && <div style="color:red;">样品认证为空</div> }
        </div>,
        okText: '确认',
        cancelText: '取消',
        onOk: () => {
          this.handleSearch();
          this.$message.success(`操作成功`);
        }
      });
    },
    onEdit() {
      this.$refs.AdmittanceDetail.open();
    },
    onCheck() {
      this.$refs.AdmittanceDetail.open();
    },
  }
}
</script>

<style lang="less" scoped>
</style>